package isoft.model;

import java.util.ArrayList;
import java.util.List;

public class Order {
    private String orderId;
    private List<OrderItem> items;
    private double totalAmount;
    private User currentUser;

    public Order(User currentUser) {
        this.orderId = orderId;
        this.items = new ArrayList<>();
        this.currentUser = currentUser;
    }

    public void addItem(OrderItem item) {
        items.add(item);
        totalAmount += item.getTotalPrice();
    }

    public List<OrderItem> getItems() {
        return items;
    }

    public double getTotalAmount() {
        return totalAmount;
    }

    public String getOrderId() {
        return orderId;
    }

    public User getUser() {
        return this.currentUser;  // 返回当前用户
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("订单ID: ").append(orderId).append("\n");
        sb.append("用户: ").append(currentUser.getUsername()).append("\n");
        sb.append("订单总金额: ").append(totalAmount).append("\n");
        sb.append("订单项: \n");
        for (OrderItem item : items) {
            sb.append(item.toString()).append("\n");
        }
        return sb.toString();
    }
}
